package com.example.backendmanage.common;

import lombok.Data;
import java.io.Serializable;
/**
 * 最终版的 JSON 统⼀返回对象
 */
@Data
public class AjaxResult implements Serializable {
    private Integer code;
    private String msg;
    private Object data;
    /**
     * 返回成功数据
     *
     * */
    public static AjaxResult success(Object data) {
        AjaxResult ajaxObject = new AjaxResult();
        ajaxObject.setCode(200);
        ajaxObject.setMsg("");
        ajaxObject.setData(data);
        return ajaxObject;
    }

    public static AjaxResult success(Object data, String msg) {
        AjaxResult ajaxObject = new AjaxResult();
        ajaxObject.setCode(200);
        ajaxObject.setMsg(msg);
        ajaxObject.setData(data);
        return ajaxObject;
    }
    /**
     * 返回成功数据
     *
     * */
    public static AjaxResult fail(Integer code, String msg) {
        AjaxResult ajaxObject = new AjaxResult();
        ajaxObject.setCode(code);
        ajaxObject.setMsg(msg);
        ajaxObject.setData("");
        return ajaxObject;
    }

    public static AjaxResult fail(Integer code, String msg, Object data) {
        AjaxResult ajaxObject = new AjaxResult();
        ajaxObject.setCode(code);
        ajaxObject.setMsg(msg);
        ajaxObject.setData(data);
        return ajaxObject;
    }
}

